package wrice.esm.compiler.fsm;

import wrice.esm.InvalidStateRuntimeException;
import wrice.esm.State;
import wrice.esm.compiler.fsm.event.*;
import wrice.esm.compiler.Parser;

public class ParserFSM {

	// factory constructor
	public static GlobalDefinitionState CreateFSM( Parser actor )
	{
		return new ParserFSM( actor ).GetInitialState();
	}

	// private constructor
	private ParserFSM( Parser actor )
	{
		actor_ = actor;
		currentState_ = GetInitialState();
	}
	
	// initial state
	private GlobalDefinitionState GetInitialState()
	{
		return globalDefinitionState_;
	}

	private Parser actor_;
	private State currentState_;

	private EventSetState eventSetState_ = new EventSetState();
	private GlobalVariableValueState globalVariableValueState_ = new GlobalVariableValueState();
	private EndState endState_ = new EndState();
	private StateDefinitionSetState stateDefinitionSetState_ = new StateDefinitionSetState();
	private EventValueState eventValueState_ = new EventValueState();
	private GlobalDefinition_InitialStateState globalDefinition_InitialStateState_ = new GlobalDefinition_InitialStateState();
	private GlobalDefinitionState globalDefinitionState_ = new GlobalDefinitionState();
	private GlobalDefinition_ActorState globalDefinition_ActorState_ = new GlobalDefinition_ActorState();
	private StateDefinitionState stateDefinitionState_ = new StateDefinitionState();


	public class EventSetState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public EventValueState event( EventNameEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, eventValueState_ );
			actor_.readEventName(evt);
			currentState_ = eventValueState_;
			return eventValueState_;
		}

		public EventSetState event( CommentLineEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, eventSetState_ );
			actor_.skipCommentLine(evt);
			//currentState_ = eventSetState_;
			return this; // eventSetState_;
		}

		public StateDefinitionSetState event( BlockEndEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionSetState_ );
			actor_.endEventSet(evt);
			currentState_ = stateDefinitionSetState_;
			return stateDefinitionSetState_;
		}

		public EventSetState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, eventSetState_ );
			actor_.skipCommentBlock(evt);
			//currentState_ = eventSetState_;
			return this; // eventSetState_;
		}


	}

	public class GlobalVariableValueState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public GlobalDefinition_InitialStateState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinition_InitialStateState_ );
			actor_.skipCommentBlock(evt);
			currentState_ = globalDefinition_InitialStateState_;
			return globalDefinition_InitialStateState_;
		}

		public GlobalDefinitionState event( StringValueEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinitionState_ );
			actor_.readGlobalVariableValue(evt);
			currentState_ = globalDefinitionState_;
			return globalDefinitionState_;
		}


	}

	public class EndState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		

	}

	public class StateDefinitionSetState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public StateDefinitionSetState event( CommentLineEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionSetState_ );
			actor_.skipCommentLine(evt);
			//currentState_ = stateDefinitionSetState_;
			return this; // stateDefinitionSetState_;
		}

		public EndState event( BlockEndEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, endState_ );
			//actor_./*Action*/( evt );
			currentState_ = endState_;
			return endState_;
		}

		public StateDefinitionSetState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionSetState_ );
			actor_.skipCommentBlock(evt);
			//currentState_ = stateDefinitionSetState_;
			return this; // stateDefinitionSetState_;
		}

		public StateDefinitionState event( StateNameEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionState_ );
			actor_.readStateName(evt);
			currentState_ = stateDefinitionState_;
			return stateDefinitionState_;
		}


	}

	public class EventValueState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public EventValueState event( CommentLineEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, eventValueState_ );
			actor_.skipCommentLine(evt);
			//currentState_ = eventValueState_;
			return this; // eventValueState_;
		}

		public EventValueState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, eventValueState_ );
			actor_.skipCommentBlock(evt);
			//currentState_ = eventValueState_;
			return this; // eventValueState_;
		}

		public EventSetState event( StateNameEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, eventSetState_ );
			actor_.readEventNextStateAndAction(evt);
			currentState_ = eventSetState_;
			return eventSetState_;
		}


	}

	public class GlobalDefinition_InitialStateState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public GlobalDefinition_InitialStateState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinition_InitialStateState_ );
			actor_.skipCommentBlock(evt);
			//currentState_ = globalDefinition_InitialStateState_;
			return this; // globalDefinition_InitialStateState_;
		}

		public GlobalDefinitionState event( StringValueEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinitionState_ );
			actor_.readGlobalInitialState(evt);
			currentState_ = globalDefinitionState_;
			return globalDefinitionState_;
		}


	}

	public class GlobalDefinitionState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public GlobalVariableValueState event( VariableNameEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalVariableValueState_ );
			actor_.readGlobalVariableName(evt);
			currentState_ = globalVariableValueState_;
			return globalVariableValueState_;
		}

		public StateDefinitionSetState event( BlockBeginEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionSetState_ );
			//actor_./*Action*/( evt );
			currentState_ = stateDefinitionSetState_;
			return stateDefinitionSetState_;
		}

		public GlobalDefinitionState event( CommentLineEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinitionState_ );
			actor_.skipCommentLine(evt);
			//currentState_ = globalDefinitionState_;
			return this; // globalDefinitionState_;
		}

		public GlobalDefinition_ActorState event( ActorEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinition_ActorState_ );
			//actor_./*Action*/( evt );
			currentState_ = globalDefinition_ActorState_;
			return globalDefinition_ActorState_;
		}

		public GlobalDefinition_InitialStateState event( InitialStateEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinition_InitialStateState_ );
			//actor_./*Action*/( evt );
			currentState_ = globalDefinition_InitialStateState_;
			return globalDefinition_InitialStateState_;
		}

		public GlobalDefinitionState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinitionState_ );
			actor_.skipCommentBlock(evt);
			//currentState_ = globalDefinitionState_;
			return this; // globalDefinitionState_;
		}


	}

	public class GlobalDefinition_ActorState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public GlobalDefinition_ActorState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinition_ActorState_ );
			actor_.skipCommentBlock(evt);
			//currentState_ = globalDefinition_ActorState_;
			return this; // globalDefinition_ActorState_;
		}

		public GlobalDefinitionState event( StringValueEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, globalDefinitionState_ );
			actor_.readGlobalActor(evt);
			currentState_ = globalDefinitionState_;
			return globalDefinitionState_;
		}


	}

	public class StateDefinitionState implements State
	{
		public boolean isCurrentState()
		{
			return this == currentState_;
		}
		
		public EventSetState event( BlockBeginEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, eventSetState_ );
			actor_.beginEventSet(evt);
			currentState_ = eventSetState_;
			return eventSetState_;
		}

		public StateDefinitionState event( CommentLineEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionState_ );
			actor_.skipCommentLine(evt);
			//currentState_ = stateDefinitionState_;
			return this; // stateDefinitionState_;
		}

		public StateDefinitionSetState event( BlockEmptyEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionSetState_ );
			actor_.emptyEventSet(evt);
			currentState_ = stateDefinitionSetState_;
			return stateDefinitionSetState_;
		}

		public StateDefinitionState event( CommentBlockEvent evt )
		{
			if( !isCurrentState() ) throw new InvalidStateRuntimeException();
			evt.setStateTransition( this, stateDefinitionState_ );
			actor_.skipCommentBlock(evt);
			//currentState_ = stateDefinitionState_;
			return this; // stateDefinitionState_;
		}


	}


}


